package com.resou.reader.signin.style2;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.resou.reader.R;
import com.resou.reader.ReSouApplication;
import com.resou.reader.data.signin.model.SignInInfo2;
import com.resou.reader.utils.ViewHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TaskListAdapter extends RecyclerView.Adapter<TaskListAdapter.TaskListHolder> {
    public static final int TASK_SIGN = 1;  //签到任务
    public static final int TASK_TIME_LIMITED = 2;  //限时任务
    public static final int TASK_DAILY = 3;  //日常任务

    private List<SignInInfo2.UserActivityBean> mActivityBeans;

    public void setActivityBeans(List<SignInInfo2.UserActivityBean> activityBeans) {
        mActivityBeans = activityBeans;
        notifyDataSetChanged();
    }

    private TaskAdapter.OnTaskInteractionListener mInteractionListener;

    public TaskListAdapter(TaskAdapter.OnTaskInteractionListener interactionListener) {
        mInteractionListener = interactionListener;
    }

    @NonNull
    @Override
    public TaskListHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        return new TaskListHolder(ViewHelper.createView(viewGroup, R.layout.recycler_item_sign_in_task_list_item));
    }

    @Override
    public void onBindViewHolder(@NonNull TaskListHolder holder, int position) {
        SignInInfo2.UserActivityBean userActivityBean = mActivityBeans.get(position);
        if (userActivityBean.getActivityDetail().size() == 0) {
            holder.itemView.setVisibility(View.GONE);
            holder.itemView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
            return;
        }
        holder.tvTitle.setText(userActivityBean.getActivityType());
        TaskAdapter taskAdapter = new TaskAdapter(userActivityBean.getActivityDetail(), userActivityBean.getActivityCode());
        taskAdapter.setInteractionListener(mInteractionListener);
        holder.recyclerView.setAdapter(taskAdapter);
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(ReSouApplication.getRSApplication()));
    }

//    @Override
//    public int getItemViewType(int position) {
//        String activityType = mActivityBeans.get(position).getActivityType();
//        if (activityType.equals("签到任务")) {
//            return TASK_SIGN;
//        }
//        if (activityType.equals("限时任务")) {
//            return TASK_TIME_LIMITED;
//        }
//        if (activityType.equals("日常任务")) {
//            return TASK_DAILY;
//        }
//        return -1;
//    }

    @Override
    public int getItemCount() {
        return mActivityBeans == null ? 0 : mActivityBeans.size();
    }

    class TaskListHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.recyclerView)
        RecyclerView recyclerView;

        public TaskListHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
